var _ = require('lodash');
var logger = require('../../lib/logger.lib');
var orderService = require('../services/order.service');


module.exports = {
    //查询所有..未判断权限
    all: function (req, res) {
        if(req.session.user == ''){
            
        }
        orderService.all(function (err, order) {
            if (err) {
                logger[err.type]().error(err);
                return res.status(500).end();
            }
            res.status(200).json(order);
        });
    },
    //查询自己的订单,跳转个人信息页面
    list: function (req, res) {
        var _id = req.session.user;

        orderService.one({ _id: _id }, function (err, order) {
            if (err) {
                logger[err.type]().error(err);
                return res.status(500).end();
            }
            return res.status(200).json(order);
        })
        //res.status(200).json('test');
    },
    //创建订单
    create: function (req, res) {
        logger.system().info('提交订单');
        var user = req.session.user;
        logger.system().info(user);

        var data = {
            userid: user,
            HouseType: req.body.HouseType,
            HouseArea: req.body.HouseArea,
            FitClassify: req.body.FitClassify,
            FitStyle: req.body.FitStyle,
            Budget: req.body.Budget,
            IsModeling: req.body.IsModeling,
            IsNeedWorkingPlan: req.body.IsNeedWorkingPlan,
            IsNeedMeasure: req.body.IsNeedMeasure,
            HouseImagePath: req.body.HouseImagePath,
            AddressDetail:req.body.AddressDetail
        }
        orderService.save({ data: data }, function (err, order) {
            if (err) {
                logger[err.type]().error(__filename, err);
                return res.status(500).end();
            }
            logger.system().info('存储' + order);
            logger.system().info('准备渲染页面');
            res.status(200).json('test');
        })
    }
};

